package com.develope.tree;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class MyArrayAdapter extends BaseAdapter {
	Activity context = null;
	ArrayList<Tree> myArray;
	int layoutId;

	public MyArrayAdapter(Activity context, int layoutId, ArrayList<Tree> arr) {
		this.context = context;
		this.layoutId = layoutId;
		this.myArray = arr;
		if(myArray == null) {
			myArray = new ArrayList<Tree>();
		}
	}
	
	@Override
	public int getCount() {
		if(myArray == null) return 0;
		return myArray.size();
	}
	
	@Override
	public Tree getItem(int position) {
		// return super.getItem(position);
		int count = getCount();
		if(count > 0 && position < count){
			return myArray.get(position);
		}
		return null;
	}
	@Override
	public View getView(int position, View converView, ViewGroup parent){
		LayoutInflater inflater=context.getLayoutInflater();
		converView = inflater.inflate(layoutId, null);
		
		if (myArray.size()>0 && position >=0){
			final TextView txtUser = (TextView) converView.findViewById(R.id.txtUser);
			final Tree tree=myArray.get(position);			
			txtUser.setText(tree.getUser());
			
			final TextView txtLo = (TextView) converView.findViewById(R.id.txtLo);
			txtLo.setText(tree.getLo());
			
			final TextView txtCay = (TextView) converView.findViewById(R.id.txtCay);
			txtCay.setText(tree.getCay());
			
			final TextView txtNgay = (TextView) converView.findViewById(R.id.txtNgay);
			txtNgay.setText(tree.getNgay());
			
			CheckBox chk = (CheckBox) converView.findViewById(R.id.chkOk);
		}
		
		return converView;

	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	
	@Override
    public boolean areAllItemsEnabled() 
    {
        return true;
    }

    @Override
    public boolean isEnabled(int arg0) 
    {
        return true;
    }
}
